import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class txtx {
    public static void main(String[] args) {
        //1.获取VoiceManager对象
        VoiceManager voiceManager=VoiceManager.getInstance();

        //2.创建默认的语音引擎
        Voice voice = voiceManager.getVoice("kevin16");
        if (voice == null) {
            System.out.println("找不到指定的语音引擎。");
        }
        //3.初始化引擎对象voice
        voice.allocate();

        // 要转换为语音的文本
        String text = "Hello, world!";

        // 将文本转换为语音并播放
        voice.speak(text);

        // 释放Voice对象
        voice.deallocate();
    }
}
